package com.example.demo.controller;

import com.example.demo.entity.faultmanage;
import com.example.demo.service.FaultmanageService;
import com.example.demo.annotation.LocalLock;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("fault")
@CrossOrigin//允许跨域
@Api(tags= "故障管理相关操作类",value = "故障管理相关操作类")
public class Faultmanage {
    @Resource
    FaultmanageService FaultmanageService;

    @PostMapping("/insert")
    @ApiOperation(value = "插入故障",notes = "传递除fkey，resetdate的数据，如果wfkey，ukey在设备信息表中查找不到则返回”机组不存在“，成功返回”插入成功“")
    public String insert(@RequestBody faultmanage faultmanage)
    {return FaultmanageService.insert(faultmanage);}

    @PostMapping("/reset")
    @LocalLock(key = "reset:")
    @ApiOperation(value = "复位运行",notes = "输入fkey自动更新复位运行时间，设备已复位返回”设备已运行“，成功返回”复位运行成功“")
    public String reset(int fkey) throws ParseException
    {return FaultmanageService.reset(fkey);}

    @PostMapping("/query")
    @ApiOperation(value = "查询故障管理表",notes = "返回所有故障管理信息")
    public List query(){return FaultmanageService.query();}
    @PostMapping("/querysuggestions")
    @ApiOperation(value = "查询故障维修建议",notes = "根据故障代码返回维修建议及置信值")
    List querysuggestions(int fcode)
    {return FaultmanageService.querysuggestions(fcode);}
}
